//
//  KqNavigationController.m
//  kq_flutter_widgets
//
//  Created by wtb on 2023/4/23.
//

#import "KqNavigationController.h"

@interface KqNavigationController ()

@end

@implementation KqNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:16],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        [appearance setShadowImage:[[UIImage alloc] init]];
        [appearance setShadowImage:[self gf_imageWithPureColor:[UIColor clearColor]]];
         appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
        [appearance setBackgroundColor:[UIColor colorWithRed:58/255.0 green:85/255.0 blue:155/255.0 alpha:1]];
        [appearance setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:16]}];
        [[UINavigationBar appearance] setScrollEdgeAppearance:appearance];
        [[UINavigationBar appearance] setStandardAppearance:appearance];
    }
    [UINavigationBar appearance].barTintColor = [UIColor colorWithRed:58/255.0 green:85/255.0 blue:155/255.0 alpha:1];
    [UINavigationBar appearance].translucent = NO;
//    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"ic_bg"] forBarMetrics:UIBarMetricsDefault];
}

- (UIImage *)gf_imageWithPureColor:(UIColor *)color {
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(3, 3), NO, [UIScreen mainScreen].scale);
    UIBezierPath* p = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 3, 3)];
    [color setFill];
    [p fill];
    UIImage* img = UIGraphicsGetImageFromCurrentImageContext();
    return img;
}

- (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
    if (self.viewControllers.count > 1) {
        self.topViewController.hidesBottomBarWhenPushed = NO;
    }
    return [super popToRootViewControllerAnimated:animated];
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        viewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
        if (self.viewControllers.count == 1) {
            viewController.hidesBottomBarWhenPushed = YES;
        }
    }
    [super pushViewController:viewController animated:animated];
}
@end
